package com.itheima.jobs;


import com.itheima.utils.QiniuUtils;
import com.itheima.utils.RedisUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Set;

/**
 * @outhor
 * @date 2020/1/13 18:22
 */

@Component
public class ClearImages {

    @Autowired
    private RedisUtil redisUtil;

    public void doClear(){
        //计算redis中两个集合的差值，获取垃圾图片名称
        Set<String> needDeleteDatas = redisUtil.sdiff("TOTAL_UPLOAD_IMGFILE_NAME", "SAVE_ADD_IMGFILE_NAME");
        for (String needDeleteData : needDeleteDatas) {
            System.out.println("needDeleteData = " + needDeleteData);
            //删除图片服务器中的图片文件
            QiniuUtils.deleteFileFromQiniu(needDeleteData);
            //删除redis中的数据
            redisUtil.srem("TOTAL_UPLOAD_IMGFILE_NAME",needDeleteData);
        }
    }
}
